package com.xxxx.server.controller;


import com.xxxx.server.pojo.Menu;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IMenuService;
import com.xxxx.server.service.IRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/system/basic/permiss")
public class RoleController {

    @Resource
    private IRoleService roleService;
    @Resource
    private IMenuService menuService;

    @ApiOperation(value = "查询所有角色")
    @GetMapping
    public List<Role> getRoleList(){
        List<Role> roleList = roleService.getRolesAll();
        return roleList;
    }

    @ApiOperation(value = "查询所有菜单")
    @GetMapping("/menus")
    public List<Menu> getMenusByRoleId(){

       return menuService.getMenusAll();
    }

    @ApiOperation(value = "根据角色id查询所有的菜单id")
    @GetMapping("/mid/{rid}")
    public List<Integer> getMidsByRids(@PathVariable Integer rid) {
        return menuService.getMidsByRid(rid);
    }
    @ApiOperation(value = "修改角色权限")
    @PutMapping("/")
    public RespBean updateMenus(Integer rid,Integer[] mids){

        return menuService.updateMenuRole(rid,mids);
    }

    @ApiOperation(value = "添加角色")
    @PostMapping("/role")
    public RespBean addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }
    @ApiOperation(value = "删除角色")
    @DeleteMapping("/role/{rid}")
    public RespBean removeRole(@PathVariable Integer rid){

        return roleService.deleteByRoleId(rid);
    }
}
